/**
 * @Author: wsl
 * @Date: 2022/2/15 13:31
 */

package com.wsl.controller.tag;


import com.wsl.message.MessageUtil;
import com.wsl.message.StatusCode;
import com.wsl.service.tag.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tag")
public class TagController extends MessageUtil {


    @Autowired
    TagService tagService;

    @RequestMapping(value = "/tagAll", method = RequestMethod.GET)
    public String tagAll() {
        return write(StatusCode.SUCCESS, tagService.getTagAll());
    }

    @RequestMapping(value = "/saveTag", method = RequestMethod.POST)
    public String saveTag(
            @RequestParam(value = "tagName", required = true) String tagName) {
        int result = tagService.setTag(tagName);
        switch (result) {
            case 1:
                return write(StatusCode.SUCCESS);
            case 0:
                return write(StatusCode.TAG_ADD_ERROR);
            default:
                return write(StatusCode.ERROR);
        }
    }

    @RequestMapping(value = "/delTag", method = RequestMethod.POST)
    public String delTag(
                         @RequestParam(value = "tagName", required = true) String tagName) {

        int i = tagService.delTag(tagName);
        switch (i) {
            case 1:
                return write(StatusCode.SUCCESS);
            case 0:
                return write(StatusCode.TAG_DELL_ERROR);
            default:
                return write(StatusCode.ERROR);
        }

    }


}